package com.tjtt.tdm.flow.dao.impl;

import java.util.List;

import org.hibernate.Query;

import com.tjtt.tdm.base.HibernateEntityDAO;
import com.tjtt.tdm.flow.bean.FlowDetailed;
import com.tjtt.tdm.flow.bean.FlowTask;
import com.tjtt.tdm.flow.bean.FlowTaskInfo;
import com.tjtt.tdm.flow.dao.IFlowformDao;
import com.tjtt.tdm.form.bean.AutoFormsField;
import com.tjtt.tdm.form.bean.AutoFormsNew;


public class FlowformDaoImpl extends HibernateEntityDAO implements IFlowformDao {

	
	public AutoFormsNew getAutoFormsNewById(String formId) {
		AutoFormsNew af = (AutoFormsNew)this.getHibernateTemplate().get(AutoFormsNew.class, Long.parseLong(formId));
		return af;
	}

	
	public List<AutoFormsField> getAutoFormsFieldByformid(String formid) {
		String hql = "from AutoFormsField a where a.formsId="+formid +" order by  SHOW_SEQ,id asc";
		List<AutoFormsField> list = getHibernateTemplate().find(hql);
		return list;
	}

	
	public FlowTask getFlowTaskById(String id) {
		FlowTask flowTask = (FlowTask)this.getHibernateTemplate().get(FlowTask.class, Long.parseLong(id));
		return flowTask;
	}
	
	public void updateFlowTask(FlowTask flowTask) {
		this.getHibernateTemplate().update(flowTask);
	}
	
	public String saveFlowDetailed(FlowDetailed flowDetailed) {
		return this.getHibernateTemplate().save(flowDetailed).toString();
	}

	
	public String saveFlowTask(FlowTask flowTask) {
		return this.getHibernateTemplate().save(flowTask).toString();
	}

	
	public FlowTaskInfo getFlowTaskInfoById(String id) {
		FlowTaskInfo flowTaskInfo = (FlowTaskInfo)this.getHibernateTemplate().get(FlowTaskInfo.class, Long.parseLong(id));
		return flowTaskInfo;
	}

	
	public String saveFlowTaskInfo(FlowTaskInfo flowTaskInfo) {
		return this.getHibernateTemplate().save(flowTaskInfo).toString();
		
	}

	
	public void updateFlowTaskInfo(FlowTaskInfo flowTaskInfo) {
		this.getHibernateTemplate().update(flowTaskInfo);
	}

	
	public void delFlowTaskInfo(FlowTaskInfo flowtaskinfo) {
		this.getHibernateTemplate().delete(flowtaskinfo);
	}

	
	public int getFlowtaskinfoStatecount(String taskid, String stateid) {
		Query query = getSession().createSQLQuery("select 1 from flow_task_info where flow_task_id='"+taskid+"' and flow_state_id='"+stateid+"'");
		List list = query.list();
		return list.size();
	}

	
	public void delFlowTaskInfoAll(String taskid) {
		// TODO Auto-generated method stub
		getSession().createSQLQuery("delete from flow_task_info where flow_task_id='"+taskid+"' ").executeUpdate();
	}
	
	public FlowDetailed getFlowDetailedById(String id) {
		FlowDetailed flowdetail = (FlowDetailed)this.getHibernateTemplate().get(FlowDetailed.class, Long.parseLong(id));
		return flowdetail;
	}
	
}
